#! /bin/bash
export LANG=en_US.UTF-8
FLAGE=
FLAGEID=
#是否输出FLAGPID
FLAGEOPID=1
#是否输出RUNTIME
RUNTIME=1
#是否输出STARTTIME
STARTTIME=0
CONN=0				#是否检查连接数
CONNMIN=
CONNMAX=
MEMORY=0			#是否检查内存
MEMORYMIN=
MEMORYMAX=
CPU=0				#是否检查CPU
CPUMIN=
CPUMAX=

THREADNUM=0			#是否检查线程数
THREADMIN=
THREADMAX=

THREADFLAP=0
THREADFLAPMIN=
THREADFLAPMAX=

JMX=0			#是否利用JMX性能参数
JMXMAX=
JMXMIN=
RESTARTUSER="iflyweb"	#重启用户
isExcuteRestart=0	#是否进行重启
SERVICEDIR=			#服务执行目录
RESTARTTHREADLIMITMIN=
RESTARTTHREADLIMITMAX=
RESTARTTHREADFLAGLIMIT=
RETRYCOUNT=
RETRYTHREADMIN=
HistoryFlapping=0
CURNUM=				#当前的性能参数



WranResultStr=		#最后形成的告警字符串
ErrorResultStr=		#最后形成的错误字符串
DataResultStr=		#性能呢个参数字符串

QUOTASTR=
quota=

TEMPTHREADFILE="./cmd/linux/DUBBO_HISTHREAD_"
TEMPTRYCOUNTFILE="./cmd/linux/DUBBO_RETRYCOUNT_"
TEMPTRYLOGFILE="./cmd/linux/DUBBO_LOG_"

function gotErr(){
	if [ "$1" -eq 0 ];then
		echo "mailstatedes=各项指标恢复正常 statedes=各项指标恢复正常|$DataResultStr"
	elif [ "$1" -eq 1 ];then 
		echo "quota=${quota} mailstatedes=$WranResultStr statedes=$WranResultStr ${QUOTASTR} |$DataResultStr"
	elif [ "$1" -eq 2 ];then 
		if [[ "${WranResultStr}" != "" ]]; then
			echo "quota=${quota} mailstatedes=${WranResultStr},${ErrorResultStr} statedes=${WranResultStr},${ErrorResultStr} ${QUOTASTR}|$DataResultStr"
			else
			echo "quota=${quota} mailstatedes=${ErrorResultStr} statedes=${ErrorResultStr} ${QUOTASTR}|$DataResultStr"
		fi
		
	elif [ "$1" -eq 3 ];then 
		if [ "$FLAGEOPID" -eq 1 ];then
			CURNUM=$FLAGEID
			parseFileds "FLAGEPID" $CURNUM $CURNUM
		fi
		echo "mailstatedes=无法获取到指标,疑似组件故障,请确认并请检查监控脚本和运维平台配置 statedes=无法获取到指标,疑似组件故障,请确认并请检查监控脚本和运维平台配置|$DataResultStr"
	fi

	exit $1
}

#返回是否服务是否存活
function isAlive(){
	isAliveStr=$(netstat -anp|grep ":$FLAGE"|grep "LISTEN"|grep -v check_dubbo|wc -l)
	if [[ "$isAliveStr" -eq 0 ]];then
		gotErr 3
	fi
	if [[ "$isAliveStr" -gt 1 ]];then
		echo "mailstatedes=你的标志项需要唯一标识一个进程 statedes=你的标志项需要唯一标识一个进程"
		showHelp
	fi
	FLAGEID=$(netstat -anp|grep ":$FLAGE"|grep "LISTEN"|awk -F " " '{print $7}'|head -n 1|sed 's/\(.*\)\/\(.*\)/\1/g')
	TEMPTHREADFILE=$TEMPTHREADFILE$FLAGE
	TEMPTRYCOUNTFILE=$TEMPTRYCOUNTFILE$FLAGE
	TEMPTRYLOGFILE=$TEMPTRYLOGFILE$FLAGE
	#获取线程历史数计算波动率
	HistoryThreadNum=`cat $TEMPTHREADFILE|head -n 1`
}


#处理连接数
function getConnNum(){
	CURNUM=$(netstat -apn | grep $FLAGEID | grep ESTABLISHED | wc -l)
}

#ps aux 4是内存 累加4的值
function getMemory(){
	CURNUM=$(ps aux | grep $FLAGEID |awk 'BEGIN{sum=0}{sum+=$4}END{print sum}')
}

#ps aux 3是CPU 累加3的值
function getCPU(){
	CURNUM=$(ps aux | grep $FLAGEID |awk 'BEGIN{sum=0}{sum+=$3}END{print sum}')
}

function getThreadNum() {
	CURNUM=$(pstree -p $FLAGEID | wc -l)
	THREADNUM=$CURNUM
	echo $THREADNUM > $TEMPTHREADFILE
}

#ps -eo pid,etime 是查询进程运行时间
function getRuntime(){
	CURNUM=$(ps -eo pid,etime | grep $FLAGEID |awk '{if($1=='$FLAGEID') print $2}')
}

#ps -eo pid,lstart是查询进程的开始时间
function getStarttime(){
	CURNUM=$(ps -eo pid,lstart | grep $FLAGEID |awk '{if($1=='$FLAGEID') print $2 ,$3 ,$4 ,$5 ,$6}')
}

function getThreadFlapping() {
	isNumber $HistoryThreadNum
	if [[ $? -eq 1 ]]; then
		temp1=$(expr $THREADNUM - $HistoryThreadNum)
		temp2=$(expr $temp1 \* 100)
		HistoryFlapping=$(expr $temp2 / $HistoryThreadNum)
	fi
	CURNUM=$HistoryFlapping
}

function appendJMXDATA() {
	CURNUM=$JMXHeapMemoryUsage
	parseFileds "JMXHeapMemoryUsage" $JMXMIN $JMXMAX
	CURNUM=$JMXNonHeapMemoryUsage
	parseFileds "JMXNonHeapMemoryUsage" $JMXMIN $JMXMAX
	CURNUM=$JMXThreadCount
	parseFileds "JMXThreadCount" $JMXMIN $JMXMAX
	CURNUM=$JMXPeekThreadCount
	parseFileds "JMXPeekThreadCount" $JMXMIN $JMXMAX
	CURNUM=$JMXClassLoadCount
	parseFileds "JMXClassLoadCount" $JMXMIN $JMXMAX
	CURNUM=$JMXStartTime
	parseFileds "JMXStartTime" $JMXMIN $JMXMAX
	CURNUM=$JMXISDeadLock
	parseFileds "JMXISDeadLock" $JMXMIN $JMXMAX
}
#然后通过各个函数获取到具体的值
#值之间的
function analysisStat(){

	if [ "$CONN" -eq 1 ];then
		getConnNum
		parseFileds "ConnectionNum" $CONNMIN $CONNMAX
	fi
	if [ "$MEMORY" -eq 1 ];then
		getMemory
		parseFileds "Memory" $MEMORYMIN $MEMORYMAX
	fi
	if [ "$CPU" -eq 1 ];then
		getCPU
		parseFileds "CPU" $CPUMIN $CPUMAX
	fi
	if [ "$THREADNUM" -eq 1 ];then
		getThreadNum
		parseFileds "ThreadNum" $THREADMIN $THREADMAX
	fi
	
	#if [ "$THREADFLAP" -eq 1 ];then
	#	getThreadFlapping
#		parseFiledFlaps "ThreadFlap" $THREADFLAPMIN $THREADFLAPMAX
#	fi

	if [ "$FLAGEOPID" -eq 1 ];then
			CURNUM=$FLAGEID
			parseFileds "FLAGEPID" $CURNUM $CURNUM
	fi
	
	JMX=0
	if [ "$JMX" -eq 1 ];then
		source ./cmd/linux/JMX_Info.sh $FLAGEID
		appendJMXDATA

		#Survivor0
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $1}')
		DataResultStr="$DataResultStr Survivor0=$CURNUM;999999;999999"

		#Survivor1
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $2}')
		DataResultStr="$DataResultStr Survivor1=$CURNUM;999999;999999"

		#EdenGen
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $3}')
		DataResultStr="$DataResultStr EdenGen=$CURNUM;999999;999999"

		#OldGen
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $4}')
		DataResultStr="$DataResultStr OldGen=$CURNUM;999999;999999"

		#PermGen
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $5}')
		DataResultStr="$DataResultStr PermGen=$CURNUM;999999;999999"

		mkdir temp_dubbo/

		#YoungGC
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $6}')
		LASTNUM=$(head -n 1 temp_dubbo/dubbo_YoungGC_"$FLAGE".temp)
		LASTTIME=$(tail -n 1 temp_dubbo/dubbo_YoungGC_"$FLAGE".temp)
		CURTIME=$(date +'%s')
		if [[ "$LASTNUM" != "" && "$LASTTIME" != "" ]]; then
			CURNUM2=`awk 'BEGIN{printf "%.2f",(('$CURNUM'-'$LASTNUM')/(('$CURTIME'-'$LASTTIME')/'60'))}'`
			DataResultStr="$DataResultStr YoungGC=$CURNUM2;999999;999999"
			
		fi
		echo $CURNUM > temp_dubbo/dubbo_YoungGC_"$FLAGE".temp
		echo $CURTIME >> temp_dubbo/dubbo_YoungGC_"$FLAGE".temp		

		#YoungGCTime
		LASTNUM=
		LASTTIME=
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $7}')
		LASTNUM=$(head -n 1 temp_dubbo/dubbo_YoungGCTime_"$FLAGE".temp)
		LASTTIME=$(tail -n 1 temp_dubbo/dubbo_YoungGCTime_"$FLAGE".temp)
		CURTIME=$(date +'%s')
		if [[ "$LASTNUM" != "" && "$LASTTIME" != "" ]]; then
			CURNUM2=`awk 'BEGIN{printf "%.2f",(('$CURNUM'-'$LASTNUM')/(('$CURTIME'-'$LASTTIME')/'60'))}'`
			DataResultStr="$DataResultStr YoungGCTime=$CURNUM2;999999;999999"
			
		fi
		echo $CURNUM > temp_dubbo/dubbo_YoungGCTime_"$FLAGE".temp
		echo $CURTIME >> temp_dubbo/dubbo_YoungGCTime_"$FLAGE".temp	


		#FullGC
		LASTNUM=
		LASTTIME=
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $8}')
		LASTNUM=$(head -n 1 temp_dubbo/dubbo_FullGC_"$FLAGE".temp)
		LASTTIME=$(tail -n 1 temp_dubbo/dubbo_FullGC_"$FLAGE".temp)
		CURTIME=$(date +'%s')
		if [[ "$LASTNUM" != "" && "$LASTTIME" != "" ]]; then
			CURNUM2=`awk 'BEGIN{printf "%.2f",(('$CURNUM'-'$LASTNUM')/(('$CURTIME'-'$LASTTIME')/'60'))}'`
			DataResultStr="$DataResultStr FullGC=$CURNUM2;999999;999999"
			
		fi
		echo $CURNUM > temp_dubbo/dubbo_FullGC_"$FLAGE".temp
		echo $CURTIME >> temp_dubbo/dubbo_FullGC_"$FLAGE".temp	

		#FGCT
		LASTNUM=
		LASTTIME=
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $9}')
		LASTNUM=$(head -n 1 temp_dubbo/dubbo_FullGCTime_"$FLAGE".temp)
		LASTTIME=$(tail -n 1 temp_dubbo/dubbo_FullGCTime_"$FLAGE".temp)
		CURTIME=$(date +'%s')
		if [[ "$LASTNUM" != "" && "$LASTTIME" != "" ]]; then
			CURNUM2=`awk 'BEGIN{printf "%.2f",(('$CURNUM'-'$LASTNUM')/(('$CURTIME'-'$LASTTIME')/'60'))}'`
			DataResultStr="$DataResultStr FullGCTime=$CURNUM2;999999;999999"
			
		fi
		echo $CURNUM > temp_dubbo/dubbo_FullGCTime_"$FLAGE".temp
		echo $CURTIME >> temp_dubbo/dubbo_FullGCTime_"$FLAGE".temp

		#GCTime
		LASTNUM=
		LASTTIME=
		CURNUM=$(jstat -gcutil $FLAGEID |tail -n 1| awk -F ' ' '{print $10}')
		LASTNUM=$(head -n 1 temp_dubbo/dubbo_GCTime_"$FLAGE".temp)
		LASTTIME=$(tail -n 1 temp_dubbo/dubbo_GCTime_"$FLAGE".temp)
		CURTIME=$(date +'%s')
		if [[ "$LASTNUM" != "" && "$LASTTIME" != "" ]]; then
			CURNUM2=`awk 'BEGIN{printf "%.2f",(('$CURNUM'-'$LASTNUM')/(('$CURTIME'-'$LASTTIME')/'60'))}'`
			DataResultStr="$DataResultStr GCTime=$CURNUM2;999999;999999"
		fi
		echo $CURNUM > temp_dubbo/dubbo_GCTime_"$FLAGE".temp
		echo $CURTIME >> temp_dubbo/dubbo_GCTime_"$FLAGE".temp
	fi
	if [ "$RUNTIME" -eq 1 ];then
			getRuntime
			parseTimeFileds "RUNTIME" $RUNTIME $RUNTIME		
	fi
	if [ "$STARTTIME" -eq 1 ];then
			getStarttime
			parseTimeFileds "STARTTIME" $STARTTIME $STARTTIME		
	fi
	
	
}
function parseTimeFileds(){
	val1=$(echo "$CURNUM $2")
	val2=$(echo "$CURNUM $3")
  DataResultStr="$DataResultStr $1=$CURNUM;$2;$3;0;0"
}

#CURNUM			当前值
#WARNLIMIT 		告警的上限
#ERRORLIMIT 	异常的上限
#判断以上三个值并拼接结果字符串
function parseFileds(){
	val1=$(echo "$CURNUM $2"| awk '{if($1<=$2){print 1}else{print 0}}')
	val2=$(echo "$CURNUM $3"| awk '{if($1<=$2){print 1}else{print 0}}')

	DataResultStr="$DataResultStr $1=$CURNUM;$2;$3;0;0"
	if [ $val1 -eq 1 ];then
		return 0
	elif [[ $val1 -eq 0 && $val2 -eq 1 ]];then
		if [[ ${WranResultStr} != "" ]]; then
			WranResultStr="${WranResultStr},"
		fi

		WranResultStr="${WranResultStr}$1当前值为${CURNUM}超过告警值${2}"

		if [[ ${quota} != "" ]]; then
			quota="${quota},"
		fi

		quota="${quota}$1"

		QUOTASTR="${QUOTASTR}$1=$1当前值为${CURNUM}超过告警值${2} "

		return 1
	else
		if [[ ${ErrorResultStr} != "" ]]; then
			ErrorResultStr="${ErrorResultStr},"
		fi
		ErrorResultStr="${ErrorResultStr}$1当前值为${CURNUM}超过紧急值${3}"

		if [[ ${quota} != "" ]]; then
			quota="${quota},"
		fi

		quota="${quota}$1"

		QUOTASTR="${QUOTASTR}$1=$1当前值为${CURNUM}超过紧急值${3} "
		
		return 2
	fi
}

function parseFiledFlaps() {
	val1=$(echo "$CURNUM $2"| awk '{if($1<=$2){print 1}else{print 0}}')
	val2=$(echo "$CURNUM $3"| awk '{if($1<=$2){print 1}else{print 0}}')

	DataResultStr="$DataResultStr $1=$CURNUM;$2;$3;0;0"
	if [[ $val1 -eq 1 || $THREADNUM -lt $RETRYTHREADMIN ]];then
		return 0
	elif [[ $val1 -eq 0 && $val2 -eq 1 ]];then
		if [[ ${WranResultStr} != "" ]]; then
			WranResultStr="${WranResultStr},"
		fi

		WranResultStr="${WranResultStr}$1当前值为${CURNUM}超过告警值${2}"

		if [[ ${quota} != "" ]]; then
			quota="${quota},"
		fi

		quota="${quota}$1"

		QUOTASTR="${QUOTASTR}$1=$1当前值为${CURNUM}超过告警值${2} "

		return 1
	else
		if [[ ${ErrorResultStr} != "" ]]; then
			ErrorResultStr="${ErrorResultStr},"
		fi
		ErrorResultStr="${ErrorResultStr}$1当前值为${CURNUM}超过紧急值${3}"

		if [[ ${quota} != "" ]]; then
			quota="${quota},"
		fi

		quota="${quota}$1"

		QUOTASTR="${QUOTASTR}$1=$1当前值为${CURNUM}超过紧急值${3} "
		
		return 2
	fi
}

#分析结果 给出给出状态
function analysisResult(){
	if [[ "$WranResultStr" == "" && "$ErrorResultStr" == "" ]];then
		gotErr 0
	elif [[ "$ErrorResultStr" == "" ]];then
		gotErr 1
	else
		gotErr 2
	fi
}

#输出错误信息并且退出程序
function showHelp(){
	if [ "$1" != "" ];then
		echo "请输入$1"
	fi
	echo "check_dubbo.sh 可以监听本地的dubbo的状态 参数如下"
	echo "check_dubbo.sh [-w 连接数,CPU,内存,线程数,线程波动率,JMX] [-c 连接数,CPU,内存,线程波动率,JMX] [-f <str>]"
	echo "-w 表示监控警告的值"
	echo "-c 表示异常值"
	echo "-f <str> 特征字符串 表示监控哪个dubbo服务"
	echo "-d <str> dubbo服务执行目录"
	echo "-t <str> dubbo服务重启线程告警值和紧急值"
	echo "-m <str> 波动dubbo服务判定的线程数下限值"
	echo "-l <str> dubbo服务重启判断次数"
	echo "-a 表示是否进行重启逻辑"
	echo "-u 表示重启的用户名"
	exit 1
}

#检查参数是不是数字
function isNumber(){
	isNum=$(echo "$1" | awk '{print($0~/^([0-9])+[\.]?([0-9])?$/)?1:0}')
	return $isNum
}

function isLarge(){

	isNumber $1
	if [[ $? -eq 0 ]]; then
		return 1
	fi

	isNumber $2
	if [[ $? -eq 0 ]]; then
		return 1
	fi

	isLarge=$(echo "$1 $2"| awk '{if($1>=$2){print 1}else{print 0}}')
	if [ $isLarge -eq 1 ];then
		return 0
	else
		return 1
	fi
}

function checkARG(){
	if [[ "$2" != "" && "$3" != "" ]];then
		isLarge "$3" "$2"
		if [[ $? -eq 1 ]]; then
			return 1
		else
			$1=1
		fi
	fi
	return 0
}
#dubbo服务重启功能
#通过比对当前线程数是否有剧烈波动&当前线程数是否高于重启值
function serviceRestartCheck(){
	#先进行是否重启判断
	if [[ $RESTARTTHREADLIMITMAX -eq "" || $THREADNUM -eq "" || "$RETRYCOUNT" -eq "" || $RESTARTTHREADLIMITMIN -eq "" ]];then
		return
	fi

	#记录时间
	echo "" >> $TEMPTRYLOGFILE
	date >> $TEMPTRYLOGFILE
	echo "CurrentThread: "$THREADNUM"       HistoryThread: "$HistoryThreadNum >> $TEMPTRYLOGFILE
	
	#判断是否需要进行重启标记
	#如果大于告警值上限则直接进行重启
	if [[ $THREADNUM -ge $RESTARTTHREADLIMITMAX ]];then
		echo "CRITICAL!!!" >> $TEMPTRYLOGFILE
		restartService
	elif [[ $THREADNUM -ge $RESTARTTHREADLIMITMIN ]];then 
		echo "WARNING!!!" >> $TEMPTRYLOGFILE
		echo 1 >>  $TEMPTRYCOUNTFILE
		#读取重启标记文件
		WarnCount=`cat $TEMPTRYCOUNTFILE |grep 1|wc -l`
		if [[ $WarnCount -ge $RETRYCOUNT ]];then
			restartService
		fi
	else
		echo "SAFE!!!" >> $TEMPTRYLOGFILE
		echo > $TEMPTRYCOUNTFILE
	fi
}
function restartService(){
		if [[ $isExcuteRestart -eq 1 ]];then
			echo > $TEMPTRYCOUNTFILE
			echo "CLEAN RESTARTFLAG" >> $TEMPTRYLOGFILE
			echo "restart service with port: "$FLAGE >> $TEMPTRYLOGFILE
			#重启dubbo服务
			RestartLog=$(su - $RESTARTUSER -c $SERVICEDIR/bin/restart.sh)
			echo $RestartLog >> $TEMPTRYLOGFILE
			echo "" >> $TEMPTRYLOGFILE
			IsSuccess=$(echo $RestartLog|grep "Starting the isservice-provider ....OK"|wc -l)
			#设置告警信息
			if [[ ${quota} != "" ]]; then
				quota="${quota},"
			fi
			echo ${quota}
			if [[ "$IsSuccess" -ne "" ]]; then
				QUOTASTR="${QUOTASTR}重启状态=成功 "
			else
				QUOTASTR="${QUOTASTR}重启状态=失败 "
			fi
		fi
}
#检查参数是否合法
#即参数是否是小数和整/数
#对于守护进程的选择 这个值可以不验证
function checkALL(){
	if [[ "$CONNMIN" != "" || "$CONNMAX" != "" ]];then
		if [[ "$CONNMAX" == "" || "$CONNMAX" == "" ]]; then
			return 1
		fi

		isLarge "$CONNMAX" "$CONNMIN"
		if [[ $? -eq 1 ]]; then
			return 1
		else
			CONN=1
		fi
	fi
	if [[ "$CPUMIN" != "" || "$CPUMAX" != "" ]];then
		if [[ "$CPUMAX" == "" || "$CPUMIN" == "" ]]; then
			return 1
		fi

		isLarge "$CPUMAX" "$CPUMIN"
		if [[ $? -eq 1 ]]; then
			return 1
		else
			CPU=1
		fi
	fi
	if [[ "$MEMORYMIN" != "" || "$MEMORYMAX" != "" ]];then

		if [[ "$MEMORYMAX" == "" || "$MEMORYMIN" == "" ]]; then
			return 1
		fi

		isLarge "$MEMORYMAX" "$MEMORYMIN"
		if [[ $? -eq 1 ]]; then
			return 1
		else
			MEMORY=1
		fi
	fi
	if [[ "$THREADMIN" != "" || "$THREADMAX" != "" ]];then

		if [[ "$THREADMIN" == "" || "$THREADMAX" == "" ]]; then
			return 1
		fi

		isLarge "$THREADMAX" "$THREADMIN"
		if [[ $? -eq 1 ]]; then
			return 1
		else
			THREADNUM=1
		fi
	fi
	
	if [[ "$THREADFLAPMIN" != "" || "$THREADFLAPMAX" != "" || "$RETRYTHREADMIN" != "" ]];then

		if [[ "$THREADFLAPMIN" == "" || "$THREADFLAPMAX" == "" || "$RETRYTHREADMIN" == "" ]]; then
			return 1
		fi

		isLarge "$THREADFLAPMAX" "$THREADFLAPMIN"
		if [[ $? -eq 1 ]]; then
			return 1
		else
			THREADFLAP=1
		fi
	fi

	if [[ "$JMXMIN" != "" || "$JMXMAX" != "" ]];then

		if [[ "$JMXMIN" == "" || "$JMXMIN" == "" ]]; then
			return 0
		fi
		isLarge "$JMXMAX" "$JMXMIN"
		if [[ $? -eq 1 ]]; then
			return 1
		else
			JMX=0
		fi
	fi
	return 0
}

function parseARG(){
	#it mean warning
	if [ $1 -eq 1 ];then
 		CONNMIN=$(echo $2 | awk -F ',' '{print $1}' | sed "s/[^0-9]//g")
 		CPUMIN=$(echo $2 | awk -F ',' '{print $2}' | sed "s/[^0-9]//g")
 		MEMORYMIN=$(echo $2 | awk -F ',' '{print $3}' | sed "s/[^0-9]//g")
		THREADMIN=$(echo $2 | awk -F ',' '{print $4}' | sed "s/[^0-9]//g")
		THREADFLAPMIN=$(echo $2 | awk -F ',' '{print $5}' | sed "s/[^0-9]//g")
		JMXMIN=$(echo $2 | awk -F ',' '{print $6}' | sed "s/[^0-9]//g")
 	else
 		CONNMAX=$(echo $2 | awk -F ',' '{print $1}' | sed "s/[^0-9]//g")
 		CPUMAX=$(echo $2 | awk -F ',' '{print $2}' | sed "s/[^0-9]//g")
 		MEMORYMAX=$(echo $2 | awk -F ',' '{print $3}' | sed "s/[^0-9]//g")
		THREADMAX=$(echo $2 | awk -F ',' '{print $4}' | sed "s/[^0-9]//g")
		THREADFLAPMAX=$(echo $2 | awk -F ',' '{print $5}' | sed "s/[^0-9]//g")
		JMXMAX=$(echo $2 | awk -F ',' '{print $6}' | sed "s/[^0-9]//g")
 	fi

}

function parseRestartArgs(){
	RESTARTTHREADLIMITMIN=$(echo $1 | awk -F ',' '{print $1}' | sed "s/[^0-9]//g")
	RESTARTTHREADLIMITMAX=$(echo $1| awk -F ',' '{print $2}' | sed "s/[^0-9]//g")
}

while getopts "w:c:f:d:t:l:m:a:u:h" arg
do
	case $arg in
		w)
			parseARG 1 "$OPTARG"
			;;
		c)
			parseARG 2 "$OPTARG"
			;;
		t)
			parseRestartArgs "$OPTARG"
			;;
		d)
			SERVICEDIR=$OPTARG
			;;
		f)
			FLAGE=$OPTARG
			;;
		l)
			RETRYCOUNT=$OPTARG
			;;		
		m)
			RETRYTHREADMIN=$OPTARG
			;;
		a)
			isExcuteRestart=1
			;;
		h)
			showHelp
			;;
		u)
			RESTARTUSER=$OPTARG
			;;
		?) 
			showHelp
			;;
	esac
done
if [[ "$FLAGE" == "" ]];then
	showHelp "特征项"
fi

checkALL
if [[ $? == 1 ]];then
	showHelp "正确参数"
fi

#插件正题部分 
#确定存活的
#启动
#分析

isAlive

analysisStat
serviceRestartCheck
analysisResult
